package com.ssh.action;

import java.util.List;

import com.opensymphony.xwork2.ActionSupport;
import com.ssh.model.User;
import com.ssh.service.UserService;

public class UserAction extends ActionSupport {
	private UserService userService;

	private List<User> userList;

	private User user;

	private int id;

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public UserService getUserService() {
		return userService;
	}

	public void setUserService(UserService userService) {
		this.userService = userService;
	}

	public List<User> getUserList() {
		return userList;
	}

	public void setUserList(List<User> userList) {
		this.userList = userList;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	@Override
	public String execute() throws Exception {
		System.out.println("action accessed");
		return SUCCESS;
	}

	public String addUser() {
		userService.saveUser(user);
		return SUCCESS;
	}

	public String modifyUser() {
		userService.modifyUser(user);
		return SUCCESS;
	}

	public String selectUser() {
		user = userService.getUserById(id);
		return SUCCESS;
	}

	public String deleteUser() {
		User user = new User();
		user.setId(id);
		userService.deleteUser(user);
		return SUCCESS;
	}

	public String showUser() {
		userList = userService.getAllUsers();
		return SUCCESS;
	}
}
